//
//  YGBannerMsgView.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/30.
//

#import "YGBannerMsgView.h"

@interface YGBannerMsgView ()

@property (nonatomic, strong) UIImageView *hospitalLogoImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *telephoneLabel;
@property (nonatomic, strong) UILabel *addressLabel;

@end
@implementation YGBannerMsgView

#pragma private

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initconstraints];
    }
    return self;
}

-(void)initView{
  
    [self addSubview:self.hospitalLogoImage];
    [self addSubview:self.nameLabel];
    [self addSubview:self.telephoneLabel];
    [self addSubview:self.addressLabel];
    
}

-(void)updateHospitalMsgWith:(YGHospitalDetailModel *)model{
    
    
    NSString *imageUrl = model.logo;
    NSURL *url = [NSURL URLWithString:imageUrl];
    [self.hospitalLogoImage sd_setImageWithURL:url];
    
    NSString *name =model.name;
    self.nameLabel.text=name;
    
    NSString *telephone =model.telephone;
    self.telephoneLabel.text=[self.telephoneLabel.text stringByAppendingString:telephone];
    
    NSString *address = model.address;
    self.addressLabel.text=[self.addressLabel.text stringByAppendingString:address];
}

-(void)initconstraints{
    
    
    [self.hospitalLogoImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top).offset(5);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-5);
            make.left.mas_equalTo(self.left).offset(10);
            make.width.mas_equalTo(120.5);
            
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top).offset(20);
            make.left.mas_equalTo(self.hospitalLogoImage.mas_right).offset(30);
            make.height.mas_equalTo(20);
            make.width.mas_equalTo(150);
            
    }];
    
    [self.telephoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(self.nameLabel.mas_left);
            make.height.mas_equalTo(20);
            make.width.mas_equalTo(150);
    }];
    
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.telephoneLabel.mas_bottom).offset(8);
            make.left.mas_equalTo(self.telephoneLabel.mas_left);
            make.height.mas_equalTo(40);
            make.width.mas_equalTo(180);
    }];
    
}


#pragma setter

- (UIImageView *)hospitalLogoImage{
    if (!_hospitalLogoImage) {
        _hospitalLogoImage = [[UIImageView alloc]init];
        
    }
    return _hospitalLogoImage;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font= [UIFont systemFontOfSize:14];
        _nameLabel.textColor=UIColorFromRGB(0x333333);
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLabel;
}

- (UILabel *)telephoneLabel{
    if (!_telephoneLabel) {
        _telephoneLabel = [[UILabel alloc]init];
        _telephoneLabel.text =@" 电话: ";
        _telephoneLabel.font = [UIFont systemFontOfSize:14];
        _telephoneLabel.textColor = UIColorFromRGB(0x333333);
        
    }
    return _telephoneLabel;
}

- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc]init];
        _addressLabel.text =@"地址：";
        _addressLabel.numberOfLines=0;
        _addressLabel.textAlignment=NSTextAlignmentCenter;
        [_addressLabel setContentMode:UIViewContentModeScaleAspectFit] ;
        _addressLabel.font = [UIFont systemFontOfSize:14];
        _addressLabel.textColor = UIColorFromRGB(0x333333);
    }
    return _addressLabel;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
